home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 301-325 / disk_313 / uucp / uucp1.lzh / src / lib / log.c < prev    next >
C/C++ Source or Header  |  1990-01-14  |  1KB  |  71 lines

  1.  
  2. /*
  3.  *  LOG.C
  4.  *
  5.  *  (C) Copyright 1989-1990 by Matthew Dillon,  All Rights Reserved.
  6.  *
  7.  *  ulog(level, ctl, args...)
  8.  */
  9.  
  10. #include <proto/all.h>
  11. #include <stdio.h>
  12. #include <stdlib.h>
  13. #include <fcntl.h>
  14. #include <time.h>
  15.  
  16. #include "log.h"
  17.  
  18. int    LogLevel = -1;
  19. int    LogToStdout = 0;
  20. char    *LogProgram = "-";
  21. char    *LogHost = "-";
  22. char    *LogWho = "-";
  23. char    *LogFile = "UUSPOOL:LOGFILE";
  24. char    LogBuf[512];
  25.  
  26. void
  27. ulog(level, ctl, arg1, arg2, arg3, arg4, arg5, arg6)
  28. int level;
  29. char *ctl;
  30. long arg1, arg2, arg3, arg4, arg5, arg6;
  31. {
  32.     long clock;
  33.     struct tm *ut;
  34.     int logfd;
  35.     int len;
  36.  
  37.     if (level > LogLevel)
  38.     return;
  39.  
  40.     (void)time(&clock);
  41.     ut = localtime(&clock);
  42.  
  43.     sprintf(LogBuf, "(%d/%d-%d:%02d:%02d) %s,%s,%s ",
  44.     ut->tm_mon+1, ut->tm_mday, ut->tm_hour, ut->tm_min, ut->tm_sec,
  45.     LogProgram,
  46.     LogHost,
  47.     LogWho
  48.     );
  49.     sprintf(LogBuf + strlen(LogBuf), ctl, arg1, arg2, arg3, arg4, arg5, arg6);
  50.  
  51.     len = strlen(LogBuf);
  52.     LogBuf[len++] = '\n';
  53.     LogBuf[len] = 0;
  54.  
  55.     DEBUG(0, "%s", LogBuf);
  56.  
  57.     if (LogToStdout) {
  58.     write(1, LogBuf, len);
  59.     return;
  60.     }
  61.  
  62.     logfd = open(LogFile, O_CREAT|O_WRONLY|O_APPEND, 0644);
  63.     if (logfd >= 0) {
  64.     write(logfd, LogBuf, len);
  65.     close(logfd);
  66.     } else {
  67.     fprintf(stderr, "Can't open %s\n", LogFile);
  68.     }
  69. }
  70.  
  71.